package com.dyw.ycgovfinance.mvp.service;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dyw.ycgovfinance.R;
import com.dyw.ycgovfinance.mvp.base.BaseFragment;
import com.dyw.ycgovfinance.util.LogUtil;

/**
 * Created by Administrator on 2017/6/20.
 */

public class FragmentServiceHome extends BaseFragment {


    //默认的是isFirstVisibles true ,刚进来的时候分两种情况
    //1.如果切过来的时候 setVisibleHint在OnCreate之前调用，那isFirstVisible为true，这个时候不进行任何操作；
    //等方法执行到onActivityCreated的时候，在执行一次setUserVisibleHint 这个时候把默认的是isFirstVisibles 设为false
    //然后这个时候调用setUserVISIBLEhINT为true  去获取数据
    //2.如果是后面再次切过来，那isFirstVisible已经为false，那就可以直接通过setUserVisibleHint获取数据了

    //代表这个界面是不是第一次被使用
    boolean isFirstUsed = true;
    private RelativeLayout rlKjks;
    private ImageView ivKjks;
    private RelativeLayout rlJxjy;
    private ImageView ivJxjy;
    private LinearLayout lyJyl;
    private LinearLayout lyYbfsjf;
    private LinearLayout lySsl;
    private LinearLayout lyFcjyjf;
    private TextView tvMore;
    private RelativeLayout rlJzxx;
    private ImageView ivJzxx;
    private TextView tvJzxxLabel;
    private RelativeLayout rlRdjd;
    private ImageView ivRdjd;
    private TextView tvRdjdLabel;
    private TextView tvZxzx;
    private TextView tvWsdc;
    private TextView tvSpzb;


    public static FragmentServiceHome newInstance() {
        FragmentServiceHome fragment = new FragmentServiceHome();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_service, container, false);
        assignView(view);
        initView();

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //fragment 可见的情况下 进行加载数据。不可见则不加载
        if (getUserVisibleHint() == true) {
            if (isFirstUsed == true) {
                isFirstUsed = false;
                setUserVisibleHint(true);
            }
            //不可见，说明fragment已经初始话完成,就直接把isFirstVisible改为false 再次切过来的时候就直接可以加载数据了
        } else {
            isFirstUsed = false;
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        // LogUtil.e("CartVisible");
        if (getUserVisibleHint()) {
            LogUtil.e("MyShuoShuoVisible");
            //如果不是firstvisible才去进行下面的操作  因为第一次很可能出现各种问题
            if (isFirstUsed == false) {

            }
        } else {
            LogUtil.e("faXianFragmentVisible");
        }
    }

    @Override
    public void initData() {

    }

    @Override
    public void assignView(View view) {
        rlKjks = (RelativeLayout) view.findViewById(R.id.rl_kjks);
        ivKjks = (ImageView) view.findViewById(R.id.iv_kjks);
        rlJxjy = (RelativeLayout) view.findViewById(R.id.rl_jxjy);
        ivJxjy = (ImageView) view.findViewById(R.id.iv_jxjy);
        lyJyl = (LinearLayout) view.findViewById(R.id.ly_jyl);
        lyYbfsjf = (LinearLayout) view.findViewById(R.id.ly_ybfsjf);
        lySsl = (LinearLayout) view.findViewById(R.id.ly_ssl);
        lyFcjyjf = (LinearLayout) view.findViewById(R.id.ly_fcjyjf);
        tvMore = (TextView) view.findViewById(R.id.tv_more);
        rlJzxx = (RelativeLayout) view.findViewById(R.id.rl_jzxx);
        ivJzxx = (ImageView) view.findViewById(R.id.iv_jzxx);
        tvJzxxLabel = (TextView) view.findViewById(R.id.tv_jzxx_label);
        rlRdjd = (RelativeLayout) view.findViewById(R.id.rl_rdjd);
        ivRdjd = (ImageView) view.findViewById(R.id.iv_rdjd);
        tvRdjdLabel = (TextView) view.findViewById(R.id.tv_rdjd_label);

        tvZxzx = (TextView) view.findViewById(R.id.tv_zxzx);
        Drawable drawable1 = getResources().getDrawable(R.mipmap.icon_zxzx);
        drawable1.setBounds(0, 0, 120, 120);//第一0是距左边距离，第二0是距上边距离，40分别是长宽
        tvZxzx.setCompoundDrawables(null, drawable1, null, null);//只放上边

        tvWsdc = (TextView) view.findViewById(R.id.tv_wsdc);
        Drawable drawable2 = getResources().getDrawable(R.mipmap.icon_wsdc);
        drawable2.setBounds(0, 0, 120, 120);//第一0是距左边距离，第二0是距上边距离，40分别是长宽
        tvWsdc.setCompoundDrawables(null, drawable2, null, null);//只放上边

        tvSpzb = (TextView) view.findViewById(R.id.tv_spzb);
        Drawable drawable3 = getResources().getDrawable(R.mipmap.icon_spzb);
        drawable3.setBounds(0, 0, 120, 120);//第一0是距左边距离，第二0是距上边距离，40分别是长宽
        tvSpzb.setCompoundDrawables(null, drawable3, null, null);//只放上边
    }

    @Override
    public void initView() {


    }
}
